<template>
    <div class="wrapper">
        <mt-header title="系统设置" class="no-bg">
            <mt-button icon="back" slot="left" @click="$router.push('/account')"></mt-button>
        </mt-header>
        <div class="list">
            <mt-cell title="登入密码" is-link @click.native="$router.push('/account/setting/editLoginPwd')">
                <span>{{userInfo && userInfo.loginPassword=='0'?'已设置':'未设置'}}</span>
            </mt-cell>
            <mt-cell title="支付密码" is-link @click.native="$router.push('/account/setting/editPayPwd')"> 
                <span>{{userInfo && userInfo.payPassword=='0'?'已设置':'未设置'}}</span>
            </mt-cell>
            <mt-cell title="手机" is-link  class="no-border" @click.native="$router.push('/account/setting/editPhone')">
                <span>{{userInfo && userInfo.mobile}}</span>
            </mt-cell>
        </div>
        <div class="blank-9"></div>
        <div class="list">
            <mt-cell title="关于DLB阅读宝" is-link  @click.native="changeToAboutDLB"></mt-cell>
            <mt-cell title="帮助中心" is-link  class="no-border" @click.native="$router.push('/account/setting/help')"></mt-cell>
        </div>
        <div class="blank-9"></div>
        <div class="list">
            <mt-cell title="意见反馈" is-link  @click.native="$router.push('/account/setting/feedback')"></mt-cell>
            <mt-cell :title="`当前版本 ${version}`" class="no-border">
            </mt-cell>
        </div>
        <div class="default-btn botBtn">
            <mt-button type="primary" size="large" @click.native="logout">退出登录</mt-button>
        </div>
    </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { MessageBox } from 'mint-ui';
import { getSystemType } from '@/utils'
import { GetAppVersion } from '@/api/api'
export default {
    data() {
        return {
            systemType : '1',
            version : ''
        };
    },
    computed: {
        ...mapGetters([
            'userInfo'
        ])
    },
    mounted(){
        if( getSystemType().type == 'android' ){
            this.systemType = '1'
        }
        if( getSystemType().type == 'ios' ){
            this.systemType = '2'
        }
        this.getAppVersion()
    },
    methods: {
        getAppVersion(){
            GetAppVersion({
                systemType:this.systemType
            }).then(res => {
                if( res.code == 200 ){
                    this.version = res.data[0].versionNumber;
                }else{
                    this.version = '';
                }
            })
        },
        changeToAboutDLB(){
            this.$router.push({
                path:'/account/setting/about',
                query:{ version:this.version }
            })
        },
        logout(){
            MessageBox({
                title:'',
                message: '确定要退出DLB阅读宝?',
                closeOnClickModal:true,
                showCancelButton:true,
            }).then(action => {
                if (action == 'confirm') {
                    this.$store.dispatch('LogOut').then(() => {
                        this.$router.push('/login')
                    })
                }else{
                    console.log('取消的回调'); 
                }
            });
        }
    }
};
</script>

<style lang="stylus" scoped>
.wrapper{
    .botBtn{
        position:absolute;
        bottom:27px;
        width:100%;
    }
}
</style>